

using System;
using System.Data;
using System.Diagnostics;
using System.Xml;
using System.ComponentModel;
using System.Collections;
using System.IO;


using CStock;
using CUtil;
using CIndicators;

//problem
//the path var.is not set after deserialization !

//TODO
//Value_Total is not reflecting the current value of the portfolio (Because it would mean an update - and reading 
//of all share data at start
//to update - call Value_TotalUpdate
namespace CStock
{
    [System.Xml.Serialization.XmlRoot()]
    public class ProgramFactory : Factory, IProgramFactory
    {
        #region fields



        IProgramContext programContext;


        #endregion

        public IProgramContext ProgramContext
        {
            get
            {
                return this.programContext;
            }
        }


        public ProgramFactory()
        {

            programContext = CStock.ProgramContext.CreateProgramContext(true);
            this.stockObjectBase = programContext as StockObjectBase;


        }



        public override bool Create_TestData()
        {
            //DeleteOldOne();

            TradeEconomyFactory tef = new TradeEconomyFactory();
            tef.Create_TestData();
            if (this.programContext != null)
                this.programContext.TradeEconomy = tef.StockObjectBase as ITradeEconomy;
            return true;
            //return base.Create_TestData();



        }
        public bool DeleteOldOne()
        {
            string myPath = this.programContext.Path;

            try
            {
                System.IO.Directory.Delete(myPath, true);
            }
            catch
            {
                //logfile is in use ...
            }

            System.IO.Directory.CreateDirectory(myPath);

            return true;
        }



        public static bool AddTestData(int i)
        {
            return true;

        }
        /// <summary>
        /// attention - new object variable for dataClass!!
        /// </summary>
        /// <returns></returns>
        public override bool DeSerialize()
        {
            if (base.DeSerialize())
            {

                this.programContext = this.stockObjectBase as IProgramContext;
                return true;

            }
            return false;




        }


    }
}
